<h1 class="crayons-title mb-4">
  <%= Email.replace_merge_tags(@email.subject, current_user) %> [<%= @email.status %>]
  <%= link_to "Edit", edit_admin_email_path(@email), class: "crayons-btn ml-3" %>
</h1>
<div class="crayons-card p-6 mb-4">
  <p>Type: <%= @email.type_of %></p>
  <p>User Query: <%= @email.user_query&.name || "No query selected" %></p>
  <% if @email.variables.present? %>
    <p>Variables: <code><%= @email.variables %></code></p>
  <% end %>
</div>
<div class="crayons-card p-6 mb-4">
  <h2 class="crayons-title mb-4">Rendered Email</h2>
  <div>
    <%= Email.replace_merge_tags(@email.body, current_user).html_safe %>
  </div>
</div>

<div class="crayons-card p-6">
  <h2 class="crayons-title mb-4">Raw HTML</h2>
  <div class="mb-4">
    <%= @email.subject %>
  </div>
  <pre>
    <%= @email.body %>
  </pre>
</div>

<div class="crayons-card p-6 mb-4 mt-4">
  <h2 class="crayons-title mb-4">Send test email</h2>
  <%= form_with(model: [:admin, @email], local: true) do |f| %>
    <div class="crayons-field">
      <%= f.label :test_email_addresses, class: "crayons-field__label" %>
      <%= f.text_field :test_email_addresses, class: "crayons-textfield", placeholder: "email@address.com, email2@other.com" %>
    </div>
    <div class="crayons-field mt-2">
      <%= f.submit "Send Test Email", class: "crayons-btn crayons-btn--primary" %>
    </div>
  <% end %>
</div>
